import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ItemCell extends StatefulWidget {
  final String? title;
  final String? imageName;
  final String? subTitle;
  final String? subImageName;
  final GestureTapCallback? onTap;
  final bool hasNewMsg;

  const ItemCell({
    super.key,
    required this.title,
    required this.imageName,
    this.subTitle,
    this.subImageName,
    this.onTap,
    this.hasNewMsg = false,
  })  : assert(title != null, "title 不能为空"),
        assert(imageName != null, "imageName 不能为空");

  @override
  State<StatefulWidget> createState() {
    return _ItemCellState();
  }
}

class _ItemCellState extends State<ItemCell> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: widget.onTap,
        onTapCancel: () {},
        onTapDown: (TapDownDetails details) {},
        child: Container(
          padding: EdgeInsets.only(left: 24.w, right: 24.w),
          decoration: BoxDecoration(
              color: Colors.white, borderRadius: BorderRadius.circular(16.w)),
          height: 96.h,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              // left
              Row(
                children: [
                  //image
                  Image(
                    image: AssetImage(widget.imageName!),
                    width: 48.h,
                    height: 48.h,
                  ),
                  const SizedBox(
                    width: 16,
                  ),
                  //title
                  Text(
                    widget.title!,
                    style: TextStyle(
                        color: const Color(0xff333333), fontSize: 32.sp),
                  ),
                ],
              ),
              // right
              Row(
                children: [
                  // subtitle
                  Text(widget.subTitle ?? ""),
                  // subimage
                  widget.subImageName != null
                      ? Image(
                          image: AssetImage(widget.subImageName!),
                          width: 24,
                        )
                      : Container(),
                  Visibility(
                    visible: widget.hasNewMsg,
                    child: Container(
                      alignment: Alignment.center,
                      width: 54.w,
                      height: 32.h,
                      decoration: BoxDecoration(
                        color: Colors.red,
                        borderRadius: BorderRadius.circular(27.w),
                      ),
                      child: Text(
                        'NEW',
                        style: TextStyle(color: Colors.white, fontSize: 20.sp),
                      ),
                    ),
                  ),

                  //箭头
                  Image(
                    image: const AssetImage(
                        'assets/images/icon_segue_arrow_grey.png'),
                    width: 48.h,
                    height: 48.h,
                    fit: BoxFit.contain,
                  ),
                ],
              ),
            ],
          ),
        ));
  }
}
